package com.mazaiting.api.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 自定义网络请求模板
 *
 * @author mazaiting
 * @create_time 2022/3/27 23:31
 */
@Configuration
@ConditionalOnMissingBean(CustomizeRestTemplateConfig.class)
public class CustomizeRestTemplateConfig {

    /**
     * 模板
     */
    @Resource
    private RestTemplate restTemplate;

    /**
     * 提供一个网络请求模板
     * @return 网络请求模板
     */
    @Bean(name = "balancedRestTemplate")
    @LoadBalanced // 负载均衡
    public RestTemplate restTemplate() {
        return restTemplate;
    }

}
